/* cs2skcb.c
 *
 * Copyright 2006-2012 David G. Barnes, Paul Bourke, Christopher Fluke
 *
 * This file is part of S2PLOT.
 *
 * S2PLOT is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * S2PLOT is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with S2PLOT.  If not, see <http://www.gnu.org/licenses/>. 
 *
 * We would appreciate it if research outcomes using S2PLOT would
 * provide the following acknowledgement:
 *
 * "Three-dimensional visualisation was conducted with the S2PLOT
 * progamming library"
 *
 * and a reference to
 *
 * D.G.Barnes, C.J.Fluke, P.D.Bourke & O.T.Parry, 2006, Publications
 * of the Astronomical Society of Australia, 23(2), 82-93.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include "s2plot.h"

/* Global variables */
char keyval;				/* Key that was pressed */
int keyp = 0;				/* Flag indicating valid key */ 

int kcb(unsigned char *key)
{
   keyp = 0;				/* Default value */
   switch (toupper(key[0])) {		/* What was pressed ? */
      case 'A' : keyval = 'a'; 		/* Set the value of key pressed */
                 keyp = 1; 		/* Set the flag */
                 return 1; 		/* Do not process "autospin" command */
                 break;	 
      case 'D' : keyval = 'd'; 		/* Set the value of key pressed */
                 keyp = 1; 		/* Set the flag */
                 return 0; 		/* Process "debug" as normal */
                 break;
   }
   return 0;				/* Process all other keys normally */
}

void cb(double *t, int *kc)
{
   char string[32];
   if (keyp) {				/* Was a valid key pressed ?*/
      sprintf(string,"You pressed: %c",keyval); 
   } else {
      sprintf(string,"Press <a> or <d>"); 
   }
   s2textxy(-1,0,0,string); 		/* Write the text to screen */
}

int main(int argc, char *argv[])
{
   s2opend("/s2mono", argc, argv);              /* Open in mono mode */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */
   
   cs2scb(cb);					/* Install dynamic callback */
   cs2skcb(kcb);				/* Install keyboard callback */

   s2show(1);                                   /* Open the s2plot window */

   return 1;
}
